﻿package plugin.shop.component
{
    import cmd.*;
    import com.sh.game.util.*;
    import flash.display.*;
    import flash.events.*;
    import manager.*;
    import morn.core.components.*;
    import plugin.component.*;

    public class NewReBayItem extends Sprite
    {
        private var back:Image;
        private var jinbiImg:Image;
        private var nameText:Label;
        private var moneyText:Label;
        private var countText:Label;
        private var Data:Object;
        private var itemImg:FlashItem;
        private var _isselected:Boolean;

        public function NewReBayItem()
        {
            this.init();
            return;
        }// end function

        private function init() : void
        {
            this.back = new Image();
            this.back.url = "png.common.icon1";
            this.back.sizeGrid = "5,5,5,5,";
            this.back.width = 165;
            this.back.height = 65;
            this.addChild(this.back);
            this.jinbiImg = new Image();
            this.jinbiImg.url = "png.common.gold";
            this.jinbiImg.x = 65;
            this.jinbiImg.y = 48 - 10;
            this.addChild(this.jinbiImg);
            this.nameText = new Label();
            this.nameText.width = 88;
            this.nameText.height = 22;
            this.nameText.x = 65;
            this.nameText.y = 12;
            this.nameText.color = MColor.V_NORMAL2;
            this.addChild(this.nameText);
            this.moneyText = new Label();
            this.moneyText.width = 100;
            this.moneyText.height = 22;
            this.moneyText.x = 90;
            this.moneyText.y = 48 - 8;
            this.moneyText.color = MColor.V_NORMAL2;
            this.addChild(this.moneyText);
            this.addEventListener(MouseEvent.MOUSE_DOWN, this.onClick);
            return;
        }// end function

        public function set data(param1:Object) : void
        {
            this.Data = param1;
            this.itemImg = new FlashItem(this.Data[4], 0.6, false, false, null, true, true);
            this.itemImg.x = 5 + 8;
            this.itemImg.y = 14 + 3 - 5;
            this.addChild(this.itemImg);
            this.nameText.text = this.Data[4].name;
            this.moneyText.text = this.Data[4].price;
            this.countText = new Label();
            this.countText.width = 20;
            this.countText.height = 22;
            this.countText.align = "right";
            this.countText.color = 16777215;
            this.countText.x = 28 + 8;
            this.countText.y = 35 + 5;
            this.countText.text = this.Data[1];
            this.countText.mouseEnabled = false;
            this.addChild(this.countText);
            return;
        }// end function

        public function get data() : Object
        {
            return this.Data;
        }// end function

        public function get isselected() : Boolean
        {
            return this._isselected;
        }// end function

        public function set isselected(param1:Boolean) : void
        {
            this._isselected = param1;
            return;
        }// end function

        private function onClick(event:MouseEvent) : void
        {
            PluginManager.instance.sendToServer("shop", CMDShop.ReBay, this.data.index);
            this.dispose();
            return;
        }// end function

        private function dispose() : void
        {
            this.Data = null;
            if (this.back && this.back.parent)
            {
                this.back.parent.removeChild(this.back);
                this.back = null;
            }
            if (this.jinbiImg && this.jinbiImg.parent)
            {
                this.jinbiImg.parent.removeChild(this.jinbiImg);
                this.jinbiImg = null;
            }
            if (this.nameText && this.nameText.parent)
            {
                this.nameText.parent.removeChild(this.nameText);
                this.nameText = null;
            }
            if (this.moneyText && this.moneyText.parent)
            {
                this.moneyText.parent.removeChild(this.moneyText);
                this.moneyText = null;
            }
            if (this.countText && this.countText.parent)
            {
                this.countText.parent.removeChild(this.countText);
                this.countText = null;
            }
            if (this.itemImg)
            {
                this.itemImg.dispose();
                this.itemImg = null;
            }
            return;
        }// end function

    }
}
